CFLAGS := -g -O0 -Wall

log := thirdparty/log.c thirdparty/log.h
json := thirdparty/cJSON.c thirdparty/cJSON.h
app_common := app/app_common.c app/app_common.h
app_message := app/app_message.c app/app_message.h
app_mqtt := app/app_mqtt.c app/app_mqtt.h
app_pthread_pool := app/app_pthread_pool.c app/app_pthread_pool.h
app_buffer := app/app_buffer.c app/app_buffer.h
app_modbus := app/app_modbus.c app/app_modbus.h
app_device := app/app_device.c app/app_device.h
ota_http := ota/ota_http.c ota/ota_http.h

clean := log_test json_test app_common_test app_message_test mqtt_test app_mqtt_test app_pthread_pool_test app_buffer_test app_modbus_test app_device_test ota_http_test
.PHONY: clean

log_test: test/log_test.c $(log)
	-gcc $(CFLAGS) $^ -o $@ -I thirdparty
	-./$@
json_test: test/json_test.c $(json) $(log)
	-gcc $(CFLAGS) $^ -o $@ -I thirdparty
	-./$@
app_common_test: test/app_common_test.c $(app_common) $(log)
	-gcc $(CFLAGS) $^ -o $@ -I app -I thirdparty
	-./$@
app_message_test: test/app_message_test.c $(app_message) $(log) $(json)
	-gcc $(CFLAGS) $^ -o $@ -I app -I thirdparty
	-./$@
mqtt_test: test/mqtt_test.c
	-gcc $(CFLAGS) $^ -o $@ -lpaho-mqtt3c
	-./$@
app_mqtt_test: test/app_mqtt_test.c $(app_mqtt) $(log)
	-gcc $(CFLAGS) $^ -o $@ -I app -I thirdparty -lpaho-mqtt3c
	-./$@
app_pthread_pool_test: test/app_pthread_pool_test.c $(app_pthread_pool) $(log)
	-gcc $(CFLAGS) $^ -o $@ -I app -I thirdparty
	-./$@
app_buffer_test: test/app_buffer_test.c $(app_buffer) $(log)
	-gcc $(CFLAGS) $^ -o $@ -I app -I thirdparty
	-./$@
app_modbus_test: test/app_modbus_test.c $(app_modbus) $(log)
	-gcc $(CFLAGS) $^ -o $@ -I app -I thirdparty -lmodbus
	-./$@
app_device_test: test/app_device_test.c $(app_device) $(log) $(app_mqtt) $(app_buffer) $(app_message) $(app_pthread_pool) $(app_modbus) $(json)
	-gcc $(CFLAGS) $^ -o $@ -I app -I thirdparty -lmodbus -lpaho-mqtt3c
	-./$@
ota_http_test: test/ota_http_test.c $(ota_http) $(log)
	-gcc $(CFLAGS) $^ -o $@ -I ota -I thirdparty -lcurl
	-./$@
clean:
	-rm -f $(clean)
